package com.jy.adscm.operation.hr.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.hr.bean.HrRecord;
import com.jy.adscm.operation.hr.mapper.mysql.HrRecordMapper;
import com.jy.adscm.operation.hr.service.HrRecordService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 人力资源-记录 服务实现类
 * </p>
 *
 * @author zyl
 * @since 2020-01-07
 */
@Service
public class HrRecordServiceImpl extends ServiceImpl<HrRecordMapper, HrRecord> implements HrRecordService {
    @Autowired
    JyUserMapper jyUserMapper;
    @Override
    public boolean insertHrRecord(HrRecord hrRecord) {
        boolean insert = super.insert(hrRecord);
        return insert;
    }

    @Override
    public boolean updateHrRecord(HrRecord hrRecord) {

        boolean b = updateById(hrRecord);

        return b;
    }


    @Override
    public boolean deletedelete(Integer id) {
        boolean b = deleteById(id);
        return b;
    }

    @Override
    public List<HrRecord> selectByHid(Integer hid, Integer type) {
        Wrapper<HrRecord> wrapper=new EntityWrapper<>();
        wrapper.eq("hid",hid);
        wrapper.eq("type",type);
        List<HrRecord> hrRecords = selectList(wrapper);
        for (HrRecord hrRecord : hrRecords) {
            if (AdscmBaseUtils.getInstance().isNotEmpty(hrRecord.getCreator(),null)){
                JyUser jyUser = jyUserMapper.selectById(hrRecord.getCreator());
                hrRecord.setCreatorName(jyUser.getName());
            }
        }
        return hrRecords;
    }
}
